//index.js
import api from '../../../utils/api.js'
//获取应用实例
var app = getApp();
Page({
  data: {
    meals: [],
    userInfo: [],
    infos: []
  },
  onLoad: function (option) {
    var that = this
    that.setData({
      userInfo: app.globalData.userInfo
    })
    that.getInfos()
  },
  onshow: function () {
    // 用户登录
    if (!app.globalData.userid) {
      app.userlogin(function () {
      });
    }
  },
  // 获取信息
  getInfos: function () {
    var that = this;
    // var page = that.data.page;
    api.getInfos({
      success: function (res) {
        console.log(res)
        var infos = res.data.result;
        that.setData({
          infos: infos,
        })
      }
    })
  },

  // 查看位置
  viewLocation: function () {
    var that = this;
    var latitude = that.data.infos[0].latitude;
    var longitude = that.data.infos[0].longitude;
    var address = that.data.infos[0].address;
    latitude = Number(latitude)
    longitude = Number(longitude)
    console.log(address, 'address')
    wx.openLocation({
      longitude: longitude,
      latitude: latitude,
      address: address,
      success(res) {
        console.log('success', res)
      },
      fail(res) {
        console.log('fail', res)
      }
    })
  },

  getCollectList: function () {
    // var userid = app.globalData.userid;

    wx.navigateTo({
      url: '../collect/collect'
    })
  },

  goForm: function () {
    var userid = app.globalData.userid;
    wx.navigateTo({
      url: '../feedback/feedback?userid' + userid
    })
  },
  /**
     * 分享
     */
  onShareAppMessage: function () {
    return {
      path: '/pages/index/index',
    }
  },

  /*联系痛快*/
  callTongkuai: function () {
    var that = this;
    var phoneNum = that.data.infos[0].phone;
    wx.makePhoneCall({
      phoneNumber: phoneNum //仅为示例，并非真实的电话号码
    })
  },

})
